package cn.hxzy.course.controller;


import cn.hxzy.common.domain.Direction;
import cn.hxzy.common.response.R;
import cn.hxzy.course.service.DirectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
@RestController
@RequestMapping("/direction")
public class DirectionController {
    @Autowired
    private DirectionService directionService;

    //查全部方向
    @RequestMapping("/select")
    public R<List<Direction>> select(){
        return R.success(directionService.selectList());
    }
    //根据学校编号查方向
    @RequestMapping("/selectBySchoolId/{schoolId}")
    public R<List<Direction>> selectBySchoolId(@PathVariable("schoolId") Integer schoolId){
        List<Direction> directions = directionService.selectBySchoolId(schoolId);
        return R.success(directions);
    }



    //根据课程编号查课程方向名称
    @GetMapping("/selectDirectionByCourseId/{courseId}")
    public R<List<Direction>> selectDirectionByCourseId(@PathVariable("courseId") Integer courseId){
        List<Direction> directions = directionService.selectDirectionByCourseId(courseId);
        for (int i = 0; i < directions.size(); i++) {
            System.out.println(directions.get(i).getDirectionName());
        }
        return R.success(directions);
    }



}

